package com.yDev.stock_runner;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;


public class Particle {
ydPoint position;
ydPoint velocity;

int originalLife;
int life;
double ageRatio;

int originalSize;
int size;

static Drawable drawable;
static Bitmap img;
//Image img;

int color;

float[] startColor={235f, 166f, 255f, 255f};
float[] endColor={89f,23f,255f,255f};
float[] deltaColor={0,0,0,0};

public Particle(){
	position=new ydPoint();
	velocity=new ydPoint();
	
	this.originalLife=0;
	this.life=0;
	
	this.originalSize=0;
	this.size=0;
	
	//color=Color.BLUE;
}

public Particle(ydPoint p, ydPoint v, int life, int size){
	position=new ydPoint(p);
	velocity=new ydPoint(v);
	
	this.originalLife=life;
	this.life=life;
	
	this.originalSize=size;
	this.size=size;
	
	//color=Color.BLUE;
	
	deltaColor[0]=(endColor[0]-startColor[0])/life;
	deltaColor[1]=(endColor[1]-startColor[1])/life;
	deltaColor[2]=(endColor[2]-startColor[2])/life;
	deltaColor[3]=(endColor[3]-startColor[3])/life;
	
	//img=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
	//img=Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("res/particleTexture2.png"));
}

public void update(){
	ageRatio=(double)life/originalLife;
	if(life>0){
		nextPosition();
		nextSize();
		nextColor();
	}
	life--;
}

public void nextPosition(){
	position.x+=velocity.x;
	position.y+=velocity.y;
}

public void nextSize(){
	size=(int) ((originalSize/(ageRatio+1)));
	return;
}

public void nextColor(){
	startColor[0]+=deltaColor[0];
	startColor[1]+=deltaColor[1];
	startColor[2]+=deltaColor[2];
	startColor[3]+=deltaColor[3];
	
	//color=new Color();
	color=Color.argb((int)startColor[3],(int)startColor[0],(int) startColor[1],(int) startColor[2]);
/*	
	Mode mMode = Mode.SRC_ATOP;
	drawable.setColorFilter(color, mMode);
	img= ((BitmapDrawable)drawable).getBitmap();*/
	//color=new Color();
}

public void draw(Canvas canvas){
	//g.drawArc;
	if(life>0){
		//g.setColor(new Color(255,100,200,(int) (255*ageRatio)));
		
		Paint p =new Paint();
		p.setColor(color);
	//	g.drawImage(img, (int)position.x, (int)position.y, size, size, color, null);
		//canvas.drawBitmap(img, (int)position.x, (int)position.y, p);
		canvas.drawCircle((int)position.x, (int)position.y, size,p);
}
}

}
